Skip to content

FEAT: Add Base91Converter (base91 binary-to-text encoding) - #4441

Open
Roman Lutz (romanlutz) wants to merge 7 commits into
microsoft:mainfrom
romanlutz:gap1-base91
Open

Roman Lutz (romanlutz) wants to merge 7 commits into
microsoft:mainfrom
romanlutz:gap1-base91

Conversation

@romanlutz

@romanlutz Roman Lutz (romanlutz) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds a pure-Python Base91 binary-to-text converter (no third-party dependency) and registers it as an ALL-only technique in the garak Encoding scenario, with a unit test and a doc example.

Part of a series splitting the gap-1 converter set into reviewable per-converter / per-base PRs (template PR — opened as draft while the layout is confirmed).

🤖 Generated with Claude Code

gap-1 converter series — splitting the esoteric cipher / encoder set into reviewable PRs (open each independently; they touch the same four registration files, so later ones rebase as earlier ones merge):

Add a pure-Python Base91 converter (no third-party dependency) and register it as
an ALL-only technique in the garak Encoding scenario, with a unit test and a doc
example.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Expanding all prevents previously saved Encoding runs from resuming, and the Base91 encoder’s 14-bit branch lacks boundary and zero-value test coverage.

2 open issues
What changed in this PR

Adds dependency-free Base91 encoding to PyRIT’s converter library and makes it available in the garak Encoding scenario.

Changes:

  • Implements UTF-8 text-to-Base91 conversion and exposes it through lazy package exports.
  • Registers Base91 as an ALL-only encoding technique, leaving the default selection unchanged.
  • Adds converter unit tests and a Python-format documentation example.
File Description
tests/​unit/​scenario/​garak/​test_encoding.py Updates the technique count and ALL-only expectations.
tests/​unit/​converter/​test_base91_converter.py Tests known vectors, Unicode, empty input, and supported types.
pyrit/​scenario/​scenarios/​garak/​encoding.py Registers the Base91 technique and converter variant.
pyrit/​converter/​base91_converter.py Implements the pure-Python Base91 converter.
pyrit/​converter/​__init__.py Adds public lazy exports for Base91Converter.
doc/​code/​converters/​1_text_to_text_converters.py Adds a Base91 conversion example.

Review effort: Balanced

# Conflicts:
#	pyrit/scenario/scenarios/garak/encoding.py
#	tests/unit/scenario/garak/test_encoding.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of d6690e8. The Base91 encoder matches the basE91 reference: two independent decoder ports round-tripped more than 190,000 inputs with no failures at this head. The remaining items are tests and docs. One P2 test-coverage item is a reply in the existing thread on test_base91_converter.py, and the resume concern on encoding.py has a reply that explains why it is out of scope here.

One item has no inline location because the PR does not change the file:

  • [P3] Add Base91 to the 'Available techniques' list and its count in doc/scanner/garak.py and doc/scanner/garak.ipynb. The PR adds the base91 technique, but the list does not name it, so readers cannot find --techniques base91 on that page. Update both files when you rebase, or refresh the list once when the converter series lands.

Comment thread pyrit/converter/base91_converter.py Resolved
Comment thread pyrit/converter/__init__.py Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.

[P3] inline:4636360934: Rerated P2 -> P3 under the changed priority rule (policy.md at e3bdbf1: missing tests are P3; P2 needs wrong behavior shown by a reproduction or trace). Same cause as local:F1, supported and not fixed: no PR test input takes the 14-bit branch (value <= 88), and the head test file still has only 'test', 'Hello World!', 'a' and empty vectors; earlier mutants of the branch pass all 10 PR tests. Impact: the untested path is correct today. Run at d6690e8 with scratch_f1_impact.py (rerate output folder, worktree .venv, run from outside the checkout): 200,000 random inputs through the head encoder; 75,863 took the 14-bit branch (115,163 groups) and 26,041 took the num_bits>7-only flush; 0 round-trip failures through an independent port of Henke's reference decoder and 0 mismatches against an independent reference-style encoder. Vectors match the reference via convert_async: 'X ' -> '""A' (14-bit), 'A' -> '%A' (flush), 'Y ' -> '~AB'. No wrong result, swallowed error or structural violation, so this is a missing test: P3, kept for the repair pass. Copilot's zero-valued-group vector alone does not discriminate the mutants; use 'X ', 'Y ' and 'A'.

[P3] inline:4690711803: Rerated P2 -> P3 under the changed priority rule. Our reply carrying F1 (same cause as inline:4636360934 and local:F1); supported and not fixed. Its P2 basis, 'a missing test for risky changed behavior', is no longer a P2 rule, and its own evidence said the code is correct today. Run at d6690e8 with scratch_f1_impact.py (rerate output folder, worktree .venv, run from outside the checkout): 200,000 random inputs through the head encoder; 75,863 took the 14-bit branch (115,163 groups) and 26,041 took the num_bits>7-only flush; 0 round-trip failures through an independent port of Henke's reference decoder and 0 mismatches against an independent reference-style encoder. Vectors match the reference via convert_async: 'X ' -> '""A' (14-bit), 'A' -> '%A' (flush), 'Y ' -> '~AB'. P3 nonblocking; the repair pass adds one parametrized test with these vectors.

[P3] inline:4690712388: Local finding F2, supported and not fixed. Dropping or renaming the base91 row in Encoding._converter_variants leaves test_encoding.py (32 passed) and related files (98 passed) green, so a lost row after a rebase builds no base91 attacks silently while the enum member stays. origin/main has the equivalent row tests for disemvowel and ubbi_dubbi. P3: the row is trivial and correct today; this is a coverage improvement.

[P3] inline:4690712399: Local finding F3, supported and not fixed. base91_converter.py:44-45 says groups are emitted at least 13 bits buffered, but line 65 is if num_bits > 13 (at least 14); the stated reason for the 14-bit case is wrong (a low-13-bit value of 88 or less gives a 14-bit value of at most 8280, still two base-91 digits). test_base91_converter.py:26 says one output char but asserts 'GB' (two). A docstring-aligned >= 13 edit raises ValueError on random input, so the risk is real. P3 documentation accuracy.

[P3] inline:4690712408: Local finding F4, supported and not fixed. Only doc/code/converters/1_text_to_text_converters.py of the jupytext pair changes; the .ipynb has Base2048 (import, print, output) and no Base91, and doc/myst.yml publishes the .ipynb, so the published page lacks the example. docs.instructions.md requires both files of the pair. Computed output for the doc prompt: fPwJ/Wwe#F!&WF<oUBUf][TX2$g%9MjL^zmfZ. P3 documentation omission.

[P3] inline:4690712416: Local finding F5, supported and not fixed. converters.instructions.md requires updating the modality table in doc/code/converters/0_converters.ipynb for new converters; the stored table has no Base91Converter at head or on origin/main (it belongs after Base64Converter). Later refreshes of that table by sibling PRs lower the impact. P3 documentation omission.

[P3] review:6052231452: Our COMMENT review body at this head. It summarises the thread replies and carries finding F6 (no inline location because the file is unchanged): doc/scanner/garak.py and doc/scanner/garak.ipynb 'Available techniques' list and count do not name base91; they are published via doc/myst.yml, and sibling PRs (#4448, #4449) updated them for their techniques. Supported and not fixed at the unchanged head. P3 documentation omission, also tracked as local:F6. Its other items refer to inline:4690711803 and inline:4690712043 assessed above.

[P3] local:F1: Rerated P2 -> P3 under the changed priority rule (feedback.json in the rerate folder). Supported and not fixed: the 10 PR tests pass for mutants of the 14-bit branch (always-13-bit, >=88, >87, >89, mask 8191) and of the flush condition, so no test guards them. The previous P2 rested on 'risky changed behavior without a test'; the new rule makes missing tests P3 and directs running the untested path instead. Run at d6690e8 with scratch_f1_impact.py (rerate output folder, worktree .venv, run from outside the checkout): 200,000 random inputs through the head encoder; 75,863 took the 14-bit branch (115,163 groups) and 26,041 took the num_bits>7-only flush; 0 round-trip failures through an independent port of Henke's reference decoder and 0 mismatches against an independent reference-style encoder. Vectors match the reference via convert_async: 'X ' -> '""A' (14-bit), 'A' -> '%A' (flush), 'Y ' -> '~AB'. The previous review also had 0 failures in more than 190,000 round trips. The output is correct, so no user-relied result changes; the fix (one parametrized vector test) does not reshape the change. P3 nonblocking for the repair pass. Extends Copilot thread 4636360934 (same cause).

[P3] local:F2: Supported P3, not fixed (feedback.json F2). Dropping or renaming the base91 row in Encoding._converter_variants leaves test_encoding.py (32 passed) and 98 related tests green; origin/main has row tests for disemvowel and ubbi_dubbi that this branch lacks until it rebases.

[P3] local:F3: Supported P3, not fixed (feedback.json F3). Docstring says at least 13 bits but code is num_bits > 13; the stated reason for the 14-bit case is wrong; test comment at line 26 says one char but asserts 'GB'.

[P3] local:F4: Supported P3, not fixed (feedback.json F4). Only the .py of the jupytext pair changes; the published .ipynb has no Base91 example.

[P3] local:F5: Supported P3, not fixed (feedback.json F5). The modality table in doc/code/converters/0_converters.ipynb has no Base91Converter, which converters.instructions.md requires for new converters.

[P3] local:F6: Supported P3, not fixed (feedback.json F6). doc/scanner/garak.py and garak.ipynb technique list and count omit base91 (file unchanged by the PR, so reported in the review body).

Re-sync the Base91Converter branch with main. Conflicts resolved
take-BOTH: keep both branches' EncodingTechnique members and
_converter_variants rows; ALL technique count is now 22
(base91 is ALL-only). Doc technique lists bumped to 22 encodings
and Base91 added to doc/scanner/garak.{py,ipynb}.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Sync doc/code/converters/1_text_to_text_converters.ipynb with its .py
  pair: add Base91Converter to the import cell, the Base91 print line, and
  the stored output line after the Base2048 output.
- Correct the _base91_encode docstring: groups emit once more than 13 bits
  (>=14) are buffered, and taking 14 bits only when the low 13 bits are <=88
  bounds the value at 91*91-1 = 8280 so it still fits two base-91 digits.
- Fix the single-byte test comment: one byte leaves 8 bits that flush as two
  characters ("GB"), not one.
- Add test_base91_technique_builds_registered_row so a deleted or misnamed
  base91 row in Encoding._converter_variants() is caught (the row is easy to
  lose during a rebase across the sibling converter PRs).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Regenerate the converter modality table in doc/code/converters/0_converters.ipynb
  so Base91Converter appears (text -> text, after Base64Converter), addressing the
  converters.instructions.md requirement for new converters.
- Add parametrized reference vectors that exercise the Base91 encoder's 14-bit branch
  ('X ' -> '""A', 'Y ' -> '~AB') and the trailing-bit flush ('A' -> '%A'), which the
  broad round-trip vectors do not discriminate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Re-sync with main (adds the Pigpen technique). Conflicts resolved
take-BOTH: keep both Base91 and Pigpen enum members, _converter_variants
rows, registered-row tests, and doc technique-list entries. ALL technique
count is now 23. Regenerated the 0_converters.ipynb modality table so both
Base91Converter and PigpenConverter appear.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants